package com.cmy.mvvm.test.ui

import android.os.Looper
import androidx.lifecycle.MutableLiveData
import com.cmy.framework.mvvm.mvvm.view_model.BaseViewModel
import com.cmy.framework_utils.log.KLog
import com.cmy.mvvm.test.api.NewsChannelsBean

/**
 * @name:
 *  HomeViewModel
 * @package:
 *  com.cmy.mvvm.test
 * @date:
 *  2023/2/1708:49
 * @author
 *    cmy
 * @description
 *
 */
class HomeViewModel : BaseViewModel() {

    private val mModel by lazy{  HomeModel() }

    val mNewsChannelsBean = MutableLiveData<NewsChannelsBean>()

    val mFailureMsg = MutableLiveData<String>()

     fun getNewsChannels(){
         KLog.i("Looper",if(Looper.getMainLooper() == Looper.myLooper()) "2主线程pre" else "2子线程pre")
        launchIO {
            mModel.getNewsChannels(
                onSuccess = {
                    KLog.i("Looper",if(Looper.getMainLooper() == Looper.myLooper()) "3主线程pre" else "3子线程pre")
                    mNewsChannelsBean.value = it

                },
                onFailure = {
//                    uiState.value =  UiState.LoadError
                    KLog.i("Looper",if(Looper.getMainLooper() == Looper.myLooper()) "3主线程pre" else "3子线程pre")
//                    mFailureMsg.value = it
                })
        }
    }



}